package cn.bluethink.eguan.core.entity;

import java.io.Serializable;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Id;
import javax.persistence.Table;

import cn.bluethink.eguan.model.core.EgCheckStatus;
import cn.bluethink.eguan.model.core.EgComment;
import cn.bluethink.eguan.model.core.EgOType;
import cn.bluethink.eguan.model.core.EgObject;
import cn.bluethink.eguan.model.core.EgUser;
/**
 * 评论实体类
 * 
 * @title 苏州中科蓝迪公司所有(c)2016-2021
 * @version 0.1.0
 * @describe
 * @author liuxn
 * @date 2018年10月24日
 */
@Table(name = "eg_comment")
public class EgCommentEntity implements Serializable {
	private static final long serialVersionUID = -8085691291618374831L;

	@Id
	private Long cmid;
	
	private String content;
	
	private Integer otype;
	
	private Long oid;
	
	/**
	 * 如果被评论对象为评论，commentator为该对象的评论者
	 */
	private Long commentator;
	
	private Long uid;
	
	private Date ctime;
	
	private Date utime;
	
	@Column(name = "root_otype")
	private Integer rootOtype;
	
	@Column(name = "root_oid")
	private Long rootOid;
	
	@Column(name = "check_status")
	private Integer checkStatus;

	public EgCommentEntity() {
		
	}
	
	/**
	 * 业务模型转实体
	 * 
	 * @param comment
	 * @param rootOid
	 * @param rootOtype
	 */
	public EgCommentEntity(EgComment comment, Long rootOid, Integer rootOtype) {
		this.cmid = comment.getId();
		this.content = comment.getName();
		this.otype = comment.getObj() == null ? null : comment.getObj().getType().getOtid();
		this.oid =  comment.getObj() == null ? null : comment.getObj().getId();
		this.commentator = comment.getCommentator() == null ? 0 : comment.getCommentator().getId();
		this.rootOtype = rootOtype;
		this.rootOid = rootOid;
		this.checkStatus = comment.getCheckStatus() == null ? EgCheckStatus.STATUS_PENDING : comment.getCheckStatus();
	}
	
	/**
	 * 实体转模型
	 * @return
	 */
	public EgComment createComment() {
		EgComment comment = new EgComment();
		comment.setId(cmid);
		comment.setName(content);

		EgObject obj = null;
		if(oid > 0 && otype > 0) {
			EgOType type = new EgOType(otype, null);
			obj = new EgObject(oid, null, type);
		}
		comment.setObj(obj);
		
		EgUser user = new EgUser(uid, null, null);
		comment.setUser(user);

		if(commentator == null) commentator = 0L;
		EgUser commentUser = new EgUser(commentator, null, null);
		comment.setCommentator(commentUser);
		
		comment.setTime(utime);
		comment.setCheckStatus(checkStatus);
		return comment;
		
	}
	
	public Long getCmid() {
		return cmid;
	}

	public void setCmid(Long cmid) {
		this.cmid = cmid;
	}

	public String getContent() {
		return content;
	}

	public void setContent(String content) {
		this.content = content;
	}

	public Integer getOtype() {
		return otype;
	}

	public void setOtype(Integer otype) {
		this.otype = otype;
	}

	public Long getOid() {
		return oid;
	}

	public void setOid(Long oid) {
		this.oid = oid;
	}

	public Long getUid() {
		return uid;
	}

	public void setUid(Long uid) {
		this.uid = uid;
	}

	public Date getCtime() {
		return ctime;
	}

	public void setCtime(Date ctime) {
		this.ctime = ctime;
	}

	public Date getUtime() {
		return utime;
	}

	public void setUtime(Date utime) {
		this.utime = utime;
	}

	public Integer getRootOtype() {
		return rootOtype;
	}

	public void setRootOtype(Integer rootOtype) {
		this.rootOtype = rootOtype;
	}

	public Long getRootOid() {
		return rootOid;
	}

	public void setRootOid(Long rootOid) {
		this.rootOid = rootOid;
	}

	public Integer getCheckStatus() {
		return checkStatus;
	}

	public void setCheckStatus(Integer checkStatus) {
		this.checkStatus = checkStatus;
	}

	public Long getCommentator() {
		return commentator;
	}

	public void setCommentator(Long commentator) {
		this.commentator = commentator;
	}
	
}
